﻿using FrameworkCore.DI;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;

namespace AiBLSmartEdu.Module.Logging.Middleware;

/// <summary>
/// 日志中间件
/// </summary>
public partial class LoggingMiddleware : IMiddleware, ITransientDependency
{
    private readonly ILogger<LoggingMiddleware> _logger;

    public LoggingMiddleware(ILogger<LoggingMiddleware> logger)
    {
        _logger = logger;
    }

    public async Task InvokeAsync(HttpContext context, RequestDelegate next)
    {
        _logger.LogInformation(context.Request.Path);
        await next(context).ConfigureAwait(false);
        _logger.LogInformation(context.Request.Path);
    }
}
